﻿namespace NoIdeaIoc;
partial class DefaultContainerBuilder : IDisposable
{
    /// <summary>
    /// 注册创建容器后的回调函数
    /// <para>创建容器后自动执行</para>
    /// </summary>
    /// <param name="action"></param>
    public void OnIocBuilded(Action<ILifeTime> action)
    {
        Startup.OnIocBuilded(action);
    }
    /// <summary>
    /// 注册创建容器后的回调函数
    /// <para>创建容器后自动执行</para>
    /// </summary>
    /// <param name="action"></param>
    public void OnIocBuilded(Func<ILifeTime, Task> action)
    {
        Startup.OnIocBuilded(action);
    }
    /// <summary>
    /// 注册扫描程序集类型时的接口
    /// </summary>
    List<AssemblyPart> assemblyParts;
    /// <summary>
    /// 添加控制器程序集(仅用于新增其他插件)
    /// </summary>
    /// <param name="assembly"></param>
    public void AddControllerAssembly(Assembly assembly)
    {
        if (assembly == null) return;
        if (assemblyParts == null) assemblyParts = new List<AssemblyPart>();
        assemblyParts.Add(new AssemblyPart(assembly));
    }
    /// <summary>
    /// 获取已添加的所有控制器插件
    /// </summary>
    /// <returns></returns>
    public IEnumerable<AssemblyPart> GetAssemblyParts()
    {
        if (assemblyParts == null) yield break;
        foreach (var part in assemblyParts) yield return part;
    }

    public void Dispose()
    {
    }
}